# @Author : Labyrinthine Leo
# @Time   : 2020.11.24
# @problem: ZDT6
# Benchmark MOP proposed by Zitzler, Deb, and Thiele
################################## Reference ################################
# E. Zitzler, K. Deb, and L. Thiele, Comparison of multiobjective           #
# evolutionary algorithms: Empirical results, Evolutionary computation,     #
# 2000, 8(2): 173-195.                                                      #
#############################################################################

import numpy as np
import platgo as pg


class ZDT6(pg.Problem):

    def __init__(self, D: int = 10) -> None:
        self.name = "ZDT6"
        self.type = "111"
        self.M = 2
        self.D = D
        lb = [0] * self.D
        ub = [1] * self.D
        self.borders = np.array([lb, ub])
        super().__init__()

    def cal_obj(self, pop: pg.Population) -> None:
        decs = pop.decs
        f1 = 1 - np.exp(-4*decs[:, 0:1]) * ((np.sin(6*np.pi*decs[:, 0:1]))**6)
        g = 1 + 9*(np.mean(decs[:, 1:], axis=1, keepdims=True))**0.25
        f2 = g * (1 - np.square(f1/g))
        pop.objv = np.hstack((f1, f2))

    def get_optimal(self) -> np.ndarray:
        # 参考点采样
        raise NotImplementedError("get optimal has not been implemented")

if __name__ == '__main__':
    z = ZDT6()
    pop = pg.Population(decs=np.random.uniform(z.borders[0], z.borders[1], (10, 10)))
    print(z.borders)
    print(pop.decs)
    z.cal_obj(pop)
    print(pop.objv)
